package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwCrowdService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by BKWJA on 2018/12/21.
 * 农家乐，景区适合人群类型控制层
 */
@Slf4j
@RequestMapping("Crowd")
@CrossOrigin(allowCredentials = "true")
@Controller
public class XwCrowdController extends IMoocExceptionHandler {

    @Autowired
    private XwCrowdService xwCrowdService;

    /**
     * 获取所有的适合人群
     * @return
     */
    @RequestMapping("getAllCrowd")
    @ResponseBody
    public JSONObject getAllCrowd(){
       return xwCrowdService.getAllCrowd();
    }

    /**
     * 农家乐、景区适合人群列表查询
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @return
     */
    @RequestMapping("/getCrowdlist")
    @ResponseBody
    public JSONObject getCrowdlist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                          @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                          @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                          @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                          @RequestParam(value = "sortfild",defaultValue = "crowd_createtime") String sortfild,
                                          @RequestParam(value = "sortway",defaultValue = "desc")String sortway){
        return xwCrowdService.getCrowdlist(pageindex,pagesize,starttime,endtime,sortfild,sortway);
    }

    /**
     * 修改，新增农家乐、景区适合人群类型信息
     * @param crowd_encryptId  景区主题游类型加密id
     * @param crowd_desc 景区主题游类型文字
     * @return
     */
    @RequestMapping("/updateCrowdinfo")
    @ResponseBody
    public JSONObject updateCrowdinfo(String crowd_encryptId,String crowd_desc){
        return xwCrowdService.updateCrowdinfo(crowd_encryptId,crowd_desc);
    }

    /**
     * 根据crowd_encryptId农家乐、景区适合人群类型加密id，删除对应的记录
     * @param crowd_encryptId
     * @return
     */
    @RequestMapping("/delCrowdinfo")
    @ResponseBody
    public JSONObject delCrowdinfo(String crowd_encryptId){
        return xwCrowdService.delCrowdinfo(crowd_encryptId);
    }


}
